package com.taotao.wechat.business;

import com.taotao.wechat.pojo.PojoTextMessage;
import org.springframework.http.HttpEntity;
import org.springframework.web.client.RestTemplate;

import java.util.LinkedHashMap;

public class CustomUtil {
    private static final String send_url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN";

    public static boolean sendTextMesaage(String appId, String openid, String content){
        HttpEntity request = new HttpEntity(new PojoTextMessage(openid, content));
        RestTemplate restTemplate = new RestTemplate();
        LinkedHashMap<String, Object> result = restTemplate.postForObject(send_url.replace("ACCESS_TOKEN", new Accesstoken(appId).getAccesstoken()),
                request, LinkedHashMap.class);

        return result.get("errcode") != null && "0".equalsIgnoreCase(result.get("errcode").toString());
    }

    public static void main(String[] args) {
        System.out.println(sendTextMesaage("wx940fdc566fac172a", "oANkGuGWZWUKcvyjGtHHie35yTAg", "Hello~"));
    }
}
